Skip to content

JIT: always home register params on wasm#130446

Merged
AndyAyersMS merged 6 commits into
dotnet:mainfrom
AndyAyersMS:wasm-home-register-params
Jul 12, 2026
Merged

JIT: always home register params on wasm#130446
AndyAyersMS merged 6 commits into
dotnet:mainfrom
AndyAyersMS:wasm-home-register-params

Conversation

@AndyAyersMS

@AndyAyersMS AndyAyersMS commented Jul 10, 2026

Copy link
Copy Markdown
Member

Always home the live params on Wasm (we do not produce or rely on the calleeRegArgMaskLiveIn). Initialize this anyways to avoid random behavior in case somebody does look at it.

Addresses the caller-side this-drop blocker in #129850.

SuperPMI (corelib crossgen2, browser): +28 bytes / 4 contexts / 0.00%.

Note

This change was authored with the assistance of GitHub Copilot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 00:13
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a wasm-specific prolog correctness issue where register-parameter homing could be skipped due to calleeRegArgMaskLiveIn not being populated on wasm (since wasm uses WasmRegAlloc rather than LSRA). The change makes wasm always invoke genHomeRegisterParams during prolog generation and updates wasm’s homing filter to use ref-counts instead of entry liveness.

Changes:

  • In genFnProlog, always call genHomeRegisterParams under TARGET_WASM instead of gating on calleeRegArgMaskLiveIn.
  • In wasm genHomeRegisterParams, switch the “spill / don’t spill” decision from fgFirstBB->bbLiveIn to lvRefCnt().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/coreclr/jit/codegenwasm.cpp Changes wasm parameter-homing eligibility check to use ref-counts rather than entry liveness.
src/coreclr/jit/codegencommon.cpp Makes wasm prolog always home register params, bypassing the calleeRegArgMaskLiveIn gate used for LSRA-based targets.

Comment thread src/coreclr/jit/codegencommon.cpp Outdated
Comment thread src/coreclr/jit/codegenwasm.cpp Outdated
…wasm

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 00:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@AndyAyersMS AndyAyersMS requested a review from adamperlin July 10, 2026 00:49
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@adamperlin PTAL
@dotnet/wasm-contrib FYI

This gets us bit farther through SPC bring up.

Comment thread src/coreclr/jit/codegencommon.cpp Outdated
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Jul 10, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/jit/codegencommon.cpp
Comment thread src/coreclr/jit/codegenwasm.cpp Outdated
Comment thread src/coreclr/jit/codegenwasm.cpp Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 18:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/jit/codegenwasm.cpp
Comment thread src/coreclr/jit/codegencommon.cpp
@AndyAyersMS

Copy link
Copy Markdown
Member Author

Looks like we still have some older versions of node out there?

Console log: 'Directed_2' from job baee6d6c-7469-4026-9784-a026a91fe247 (azurelinux.3.amd64.open.rt) using docker image mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-26.04-helix-webassembly-amd64@sha256:3ef1314b50ac039078f6406d649d5ac72715deccd07bcbfe3dd43fa438be3fbd on a00LCE7
...
Running: node --stack-size=8192 /root/helix/work/correlation/corerun.js -c /root/helix/work/correlation /root/helix/work/workitem/e/JIT/Directed/Directed_2/Directed_2.dll
failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): invalid value type 'exn', enable with --experimental-wasm-exnref @+58
warning: Loading from a file URI (file:///root/helix/work/correlation/corerun.wasm) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing
Aborted(CompileError: WebAssembly.instantiate(): invalid value type 'exn', enable with --experimental-wasm-exnref @+58)
file:///root/helix/work/correlation/corerun.js:461
  /** @suppress {checkTypes} */ var e = new WebAssembly.RuntimeError(what);
                                        ^

RuntimeError: Aborted(CompileError: WebAssembly.instantiate(): invalid value type 'exn', enable with --experimental-wasm-exnref @+58)
    at abort (file:///root/helix/work/correlation/corerun.js:461:41)
    at instantiateArrayBuffer (file:///root/helix/work/correlation/corerun.js:530:5)
    at async createWasm (file:///root/helix/work/correlation/corerun.js:608:16)
    at async createDotnetRuntime (file:///root/helix/work/correlation/corerun.js:7517:15)

Node.js v23.11.1

Copilot AI review requested due to automatic review settings July 11, 2026 14:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/jit/codegencommon.cpp
Comment thread src/coreclr/jit/codegencommon.cpp
@pavelsavara

Copy link
Copy Markdown
Member

invalid value type 'exn', enable with --experimental-wasm-exnref @+58)
Node.js v23.11.1

Node version seems ok, we just need to pass --experimental-wasm-exnref in more scripts
#130550

Copilot AI review requested due to automatic review settings July 11, 2026 18:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/jit/codegenwasm.cpp
Comment thread src/coreclr/jit/codegencommon.cpp
Comment thread src/coreclr/jit/codegencommon.cpp
@pavelsavara

Copy link
Copy Markdown
Member

Node version seems ok, we just need to pass --experimental-wasm-exnref in more scripts #130550

Fixed now @AndyAyersMS

Log

node version: v23.11.1
Timeout in ms: 900000
Running: node --experimental-wasm-exnref --stack-size=8192 /root/helix/work/correlation/corerun.js -c /root/helix/work/correlation /root/helix/work/workitem/e/JIT/Directed/Directed_2/Directed_2.dll
19:04:04.786 Running test: JIT/Directed/perffix/primitivevt/callconv3_d/callconv3_d.dll
PASSED

...

PASSED
19:04:05.416 Passed test: JIT/Directed/shift/uint16_ro/uint16_ro.dll
Kill watchdog with PID 46
Expected: 100
Actual: 100
END EXECUTION - PASSED

@AndyAyersMS AndyAyersMS enabled auto-merge (squash) July 11, 2026 23:20
@AndyAyersMS AndyAyersMS merged commit c9265d7 into dotnet:main Jul 12, 2026
140 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 13, 2026
lewing added a commit to lewing/runtime that referenced this pull request Jul 13, 2026
…d on entry liveness)

Squashed net diff of dotnet#130446 onto the R2R prototype branch to
fix the release-only wasm param-homing miscompile (this/args read from a
frame home the prolog zeroed but never populated). Cherry-picking the 3
individual commits churns codegenwasm.cpp through an intermediate refcnt-based
check; the net diff is the codegencommon.cpp calleeRegArgMaskLiveIn init +
unconditional genHomeRegisterParams call, plus a comment in codegenwasm.cpp.

Prototype-only; for the future WASI R2R PR, not for dotnet#130051.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing added a commit to lewing/runtime that referenced this pull request Jul 13, 2026
Rebaselines the WASI R2R prototype onto current main (67 commits, now includes
dotnet#130446 param-homing merged upstream 07-12). 4 trivial conflicts resolved in favor
of origin/main (jiteeversionguid.h GUID token; wasi PAL stubs/file/map comment+null-check
polish that landed via dotnet#130051 squash). dotnet#130446 de-duplicated cleanly (our cherry-pick
== main's merged change). Prototype-only delta preserved: dotnet#130384 (inline pinvokes,
still draft upstream), GAP1 (crossgen2 Program.cs +Wasi optimistic-ISA), static-compose
corerun glue + JIT-EE WasmWellKnownGlobalSymbol additions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing added a commit to lewing/runtime that referenced this pull request Jul 13, 2026
…arity

Cherry-pick InitHelpers.cs from AndyAyersMS:next-blocker-spc — InitClass and
InitInstantiatedClass return void* (null) instead of void, so the compiled wasm
call_indirect signature matches the interp's value-returning P_ helper convention.
Fixes the class-init helper arity mismatch (Console.cctor trap) that the rebaselined
corelib-R2R composite hit at func 61854 after Gates 1+2 (dotnet#130384/dotnet#130446).

Prototype-only; for the future WASI R2R PR.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Always home the live params on Wasm (we do not produce or rely on the
`calleeRegArgMaskLiveIn`). Initialize this anyways to avoid random
behavior in case somebody does look at it.

Addresses the caller-side `this`-drop blocker in #129850.

SuperPMI (corelib crossgen2, browser): +28 bytes / 4 contexts / 0.00%.

> [!NOTE]
> This change was authored with the assistance of GitHub Copilot.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Pavel Savara <pavel.savara@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants